package com.peiqi.aiproject.controller;

import cn.hutool.http.HttpStatus;
import com.peiqi.aiproject.domain.User;
import com.peiqi.aiproject.domain.dto.ValidSmsDTO;
import com.peiqi.aiproject.domain.vo.ResponseVO;
import com.peiqi.aiproject.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

/**
 * 用户相关接口
 * @author yulian
 */
@RestController
@RequestMapping("/users")
public class UserController {
    @Resource
    UserService userService;

    /**
     * 获取用户信息接口
     * @return User 用户对象
     */
    @GetMapping("/user-info")
    public ResponseVO<User> getUsers(HttpServletRequest request){
        User user = userService.getUsers();
        return ResponseVO.success(HttpStatus.HTTP_OK,user);
    }

    /**
     * 手机号注册用户
     * @param validSmsDTO 注册数据
     * @return void
     */
    @PostMapping("/reg")
    public ResponseVO<String> saveUser(@RequestBody ValidSmsDTO validSmsDTO){
        String token = userService.saveUser(validSmsDTO);
        return ResponseVO.success(HttpStatus.HTTP_CREATED,token);
    }
}
